package com.chao.wind3j.service.impl;

import com.chao.wind3j.mapper.Wind3RequestDao;
import com.chao.wind3j.model.dataBaseModel.Wind3Request;
import com.chao.wind3j.service.Wind3RequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.function.Function;

@Service("Wind3RequestService")
public class Wind3RequestServiceImpl implements Wind3RequestService {

  @Autowired
  private Wind3RequestDao wind3RequestDao;

  @Override
  public void insertWind3Request(Wind3Request wind3Request) {
    if (null == wind3Request.getRequestId()) {
      wind3Request.setRequestId(UUID.randomUUID().toString());
    }
    this.wind3RequestDao.insert(wind3Request);
  }

  @Override
  public void deleteWind3Request(Wind3Request wind3Request) {
    var wind3RequestList = this.wind3RequestDao.getList(wind3Request);
    var ids = (String[])wind3RequestList.stream().map(Wind3Request::getRequestId).toArray();
    this.wind3RequestDao.deleteByIds(ids);
  }

  @Override
  public void updateWind3Request(Wind3Request wind3Request) {
    this.wind3RequestDao.updateById(wind3Request);
  }
}
